<%--
  Author: lwx
  Date: 2021/05/08
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>学生信息修改</title>
    <base href="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/">
    <link rel="stylesheet" href="css/form.css">
</head>
<body onload="setSelectChecked()">
<a href="stu/list" class="previous">&laquo; 返回</a>

<form action="stu/modify" onsubmit="return checkForm();" method="post">
    <div class="from">
        <div class="submit">
            <span class="form_title">学生信息修改</span>
            <div class="form_input">
                <span>id：</span>
                <input class="inputs" name="id" type="text" value="${studentInfo.id}" readonly/>
            </div>
            <div class="form_input">
                <span>姓名：</span>
                <input class="inputs" id="sName" name="sName" type="text" value="${studentInfo.sName}"/>
            </div>
            <div class="form_input">
                <span>班级:</span>
                <input class="inputs" id="sClass" name="sClass" type="text" value="${studentInfo.sClass}"/>
            </div>
            <div class="form_input">
                <span>学号：</span>
                <input class="inputs" id="sNo" name="sNo" type="text" value="${studentInfo.sNo}"/>
            </div>
            <div class="form_input">
                <span>系部：</span>
                <input type="hidden" id="collegeId" value="${studentInfo.sCollege}">
                <select name="sCollege" id="college">
                    <option value="数学与信息工程学院">数学与信息工程学院</option>
                    <option value="外国语学院">外国语学院</option>
                    <option value="师范教育学院">师范教育学院</option>
                    <option value="生命科学学院">生命科学学院</option>
                    <option value="资源工程学院">资源工程学院</option>
                    <option value="经济与管理学院">经济与管理学院</option>
                    <option value="化学与材料学院">化学与材料学院</option>
                    <option value="体育与健康学院">体育与健康学院</option>
                    <option value="马克思主义学院">马克思主义学院</option>
                    <option value="传播与设计学院">传播与设计学院</option>
                    <option value="物理与机电工程学院">物理与机电工程学院</option>
                </select><br/><!--下拉栏-->
            </div>
            <div class="form_input">
                <span>性别：</span>
                <input ${studentInfo.sSex == '男'?'checked="true"':''} type="radio" name="sSex" value="男"/>男&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input ${studentInfo.sSex == '男'?'':'checked="true"'} type="radio" name="sSex" value="女"/>女
            </div>
            <div class="btn_submit">
                <button class="btn" type="submit">提交</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="stu/list" class="back">
                    <button class="home_href" type="button">返回</button>
                </a>
            </div>
        </div>
    </div>
</form>
</body>
<script type="text/javascript">
    function checkForm(){
        var sName = document.getElementById("sName").value;
        if(sName==""){
            alert("姓名不能为空!");
            return false;
        }
        var sClass = document.getElementById("sClass").value;
        if(sClass==""){
            alert("班级不能为空!");
            return false;
        }
        var sNo = document.getElementById("sNo").value;
        if(sNo == "" || sNo == null) {
            alert("学号不能为空！");
            return false;
        } else if (!checkIdReg(sNo)) {
            alert("学号必须为11位数字！");
            return false;
        }
    }

    function checkIdReg(theObj) {//正则判断学号是否合格
        var reg = /^\d{11}$/;
        if (reg.test(theObj)) {
            return true;
        }
        return false;
    }
    function setSelectChecked() {
        var collegeId = document.getElementById('collegeId').value;
        var college = document.getElementById('college');
        for (var i = 0; i < college.options.length; i++) {
            if (college.options[i].value == collegeId) {
                college.options[i].selected = true;
                break;
            }
        }
    }

</script>
</html>
